﻿<%@ WebHandler Language="C#" Class="RolerHandler" %>

using System;
using System.Web;

public class RolerHandler : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {   
        try
        {
            string strRoleID = string.Empty, strRoleName = string.Empty, strRoleDesc = string.Empty, strSelectRole = string.Empty,strType = string.Empty;
            SCS.Model.SCS_Roler _rolerModel = new SCS.Model.SCS_Roler();
                            SCS.BLL.SCS_Roler _rolerBll = new SCS.BLL.SCS_Roler();
            
            if (context.Request.QueryString["type"] != null)
            {
                strType = context.Request.QueryString["type"].ToString();
            }

            SCS.Model.SCS_Operating_Log oOperatorLog = new SCS.Model.SCS_Operating_Log();

            oOperatorLog.Log_IP_Adress = SCS.Common.ComputeInfo.getRemoteIP();
            oOperatorLog.Log_MAC_Address = "";
            oOperatorLog.Log_TimeStamp = DateTime.Now;
            oOperatorLog.Log_User_ID = "zhangli";//from session
            oOperatorLog.Object_Name = "";
            
            if (strType.ToLower() == "update")
            {
                
                if (context.Request.QueryString["roleid"] != null)
                {
                    strRoleID = context.Request.QueryString["roleid"].ToString();
                    _rolerModel.Roler_ID = int.Parse(strRoleID);
                }

                if (context.Request.QueryString["rolename"] != null)
                {
                    strRoleName = context.Request.QueryString["rolename"].ToString();
                    _rolerModel.Roler_Name = strRoleName;
                }

                if (context.Request.QueryString["rolerdesc"] != null)
                {
                    strRoleDesc = context.Request.QueryString["rolerdesc"].ToString();
                    _rolerModel.Roler_Description = strRoleDesc;
                }

                if (context.Request.QueryString["rolerenable"] != null)
                {
                    strSelectRole = context.Request.QueryString["rolerenable"].ToString();

                    if (strSelectRole == "启用")
                    {
                        _rolerModel.Roler_IsEnable = 1;
                    }
                    else if (strSelectRole == "禁用")
                    {
                        _rolerModel.Roler_IsEnable = 0;
                    }

                }

                if (strSelectRole == "启用")
                {
                    oOperatorLog.Log_Description = "启用角色";
                }
                else if (strSelectRole == "禁用")
                {
                    oOperatorLog.Log_Description = "禁用角色";
                }

                if (_rolerBll.UpdateRoler(_rolerModel, oOperatorLog) > 0) 
                {
                    context.Response.Write("1");
                }
                else
                {
                    context.Response.Write("0");
                }
            }
            else if (strType.ToLower() == "delete") 
            {
                if (context.Request.QueryString["roleid"] != null)
                {
                    strRoleID = context.Request.QueryString["roleid"].ToString();
                    oOperatorLog.Log_Description = "删除角色";

                    if (_rolerBll.Delete(int.Parse(strRoleID), oOperatorLog)) 
                    {
                        context.Response.Write("1");
                    }
                    else
                    {
                        context.Response.Write("0");
                    }
                }
            }
        }
        catch (Exception)
        {
            context.Response.Write("0");
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}